<template>
  <div :style="styleItem">
    <div id="InventoryCharts"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  name: "InventoryCharts",
  props: {
    styleItem: {
      type: Object,
      default: () => {},
    },
    currentDate: {
      type: Array,
      default: () => [],
    },
    checkSerires: {
      type: Array,
      default: () => [],
    },
    data1: {
      type: Array,
      default: () => [],
    },
    scanData: {
      type: Array,
      default: () => [],
    }
  },
  data() {
    return {
      myChart: null,
      scanDataList: [],
      scanTimeList: []
    };
  },
  mounted() {
    this.showChart();
  },
  methods: {
    getMoreData() {
      this.scanDataList = []
      this.scanTimeList = []

      this.scanData.map(m => {
        

          this.scanDataList.push(m.total)
          this.scanTimeList.push(m.day)
        
      })
    },
    reloadChart() {
      // console.log("mmmmmmmmmmmm", this.styleItem);
      this.myChart.clear();
      this.getMoreData()
      this.showChart();
    },
    showChart() {
      // console.log('showChart-showChart')

      if (
        this.myChart != null &&
        this.myChart != "" &&
        this.myChart != "undefined"
      ) {
        this.myChart.dispose();
      }
      this.myChart = echarts.init(document.getElementById("InventoryCharts"));
      let option = {
        tooltip: {
          trigger: "axis",
          ayisPointer: {
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
          },
        },
        grid: {
          top: "15%", // 组件离容器上侧的距离,百分比字符串或整型数字
          left: "5%", // 组件离容器左侧的距离,百分比字符串或整型数字
          right: "5%",
          bottom: "5%",
          containLabel: true, //grid 区域是否包含坐标轴的刻度标签，
        },
        // legend: {
        //   icon: "rect",
        //   top: "2%",
        //   bottom: 0,
        //   itemWidth: this.$fontSize.fontSize(0.12),
        //   itemHeight: this.$fontSize.fontSize(0.12),
        //   itemGap: this.$fontSize.fontSize(0.2),
        //   textStyle: {
        //     color: "#fff",
        //     fontSize: this.$fontSize.fontSize(0.12),
        //   },
        //   // data: ["江苏"],
        // },
        barWidth: this.$fontSize.fontSize(0.24),
        yAxis: {
          type: "value",
          splitLine: {
            lineStyle: {
              color: "rgba(255,255,255,0.2)",
            },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            //  改变x轴颜色
            lineStyle: {
              color: "rgba(69, 240, 234, 1)",
            },
          },
          axisLabel: {
            //  改变x轴字体颜色和大小
            textStyle: {
              color: "#ccc",
              fontSize: this.$fontSize.fontSize(0.12),
            },
          },
        },
        xAxis: [
          {
            type: "category",
            data: this.scanTimeList,
            axisTick: {
              alignWithLabel: true,
            },
            axisLine: {
              //  改变x轴颜色
              lineStyle: {
                color: "rgba(69, 240, 234, 1)",
              },
            },
            axisLabel: {
              // interval: 0,
              // rotate: -5,
              // rotate: 8,
              color: "#ccc",
              //fontFamily: 'PingFangSC',
              fontSize: this.$fontSize.fontSize(0.12),
              // fontWeight: 300
            },
          },
        ],
        series: [
          {
            "type": "bar",
            "name": "盘点",
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#71FF74",
                  },

                  {
                    offset: 1,
                    color: "#35B61F",
                  },
                ]),
                "borderWidth": 2
              },
            },
            "showBackground": true,
            "backgroundStyle": {
                "color": "rgba(180, 180, 180, 0.2)"
            },
            "data": this.scanDataList
          }
        ]
        // this.checkSerires, */
      };
      // showBackground: true,
      console.log(this.checkSerires, "this.checkSerires");
      this.myChart.setOption(option);
      // window.addEventListener("resize", function() {
      //   this.myChart.resize();
      // });
    },
  },
};
</script>

<style lang="scss">
#InventoryCharts {
  width: 100%;
  height: 24vh;
}
</style>
